/*
 * Example6Graphics.java  0.4.0 / 2010-10-22
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
package com.cute4j.examples;

import com.cute4j.swing.Component;
import com.cute4j.swing.Swing;
import com.cute4j.swing.events.SwingEvent;
import com.cute4j.swing.graphics.BasicStroke;
import com.cute4j.swing.graphics.Color;
import com.cute4j.swing.graphics.CubicCurve;
import com.cute4j.swing.graphics.Ellipse;
import com.cute4j.swing.graphics.GradientPaint;
import com.cute4j.swing.graphics.Graphics;
import com.cute4j.swing.graphics.Line;
import com.cute4j.swing.graphics.Rectangle;
import com.cute4j.swing.graphics.RoundRectangle;
import com.cute4j.swing.graphics.Stroke;
import com.cute4j.swing.graphics.TexturePaint;

/**
 * Graphics Example.
 */
public class Example6Graphics extends Component {

  private final GradientPaint gradientPaint;
  private final TexturePaint texturePaint;
  private final BasicStroke basicStroke;

  /**
   * Constructs new Example6Graphics object.
   */
  public Example6Graphics() {
    setName("Graphics");
    setFixedSize(500, 420);
    enableEvents(SwingEvent.PAINT_EVENT_MASK);
    basicStroke = new BasicStroke(2, BasicStroke.CAP_SQUARE,
                                  BasicStroke.JOIN_MITER, 10.0f,
                                  new float[] {2f, 4f});
    gradientPaint = new GradientPaint(100, 180, Color.DARK_RED, 180, 240,
                                      Color.DARK_GREEN, true);
    texturePaint = new TexturePaint(Swing.crateImage(
                        Example6Graphics.class.getResource("GreenTeaCup.png")));
  }

  protected void paintComponent(Graphics g) {
    g.draw(new Line(20, 80, 80, 20));
    g.draw(new Rectangle(100, 20, 80, 60));
    g.draw(new Ellipse(200, 20, 80, 60));
    g.draw(new RoundRectangle(300, 20, 80, 60, 20, 20));
    g.draw(new CubicCurve(400, 20, 440, 20, 400, 80, 480, 80));
    Stroke s = g.getStroke();
    g.setStroke(basicStroke);
    g.draw(new Line(20, 160, 80, 100));
    g.draw(new Rectangle(100, 100, 80, 60));
    g.draw(new Ellipse(200, 100, 80, 60));
    g.draw(new RoundRectangle(300, 100, 80, 60, 20, 20));
    g.draw(new CubicCurve(400, 100, 440, 100, 400, 160, 480, 160));
    g.setColor(Color.DARK_BLUE);
    g.setStroke(s);
    g.draw(new Line(20, 240, 80, 180));
    g.fill(new Rectangle(100, 180, 80, 60));
    g.draw(new Rectangle(100, 180, 80, 60));
    g.fill(new Ellipse(200, 180, 80, 60));
    g.draw(new Ellipse(200, 180, 80, 60));
    g.fill(new RoundRectangle(300, 180, 80, 60, 20, 20));
    g.draw(new RoundRectangle(300, 180, 80, 60, 20, 20));
    g.fill(new CubicCurve(400, 180, 440, 180, 400, 240, 480, 240));
    g.draw(new CubicCurve(400, 180, 440, 180, 400, 240, 480, 240));
    g.setPaint(gradientPaint);
    g.draw(new Line(20, 320, 80, 260));
    g.fill(new Rectangle(100, 260, 80, 60));
    g.draw(new Rectangle(100, 260, 80, 60));
    g.fill(new Ellipse(200, 260, 80, 60));
    g.draw(new Ellipse(200, 260, 80, 60));
    g.fill(new RoundRectangle(300, 260, 80, 60, 20, 20));
    g.draw(new RoundRectangle(300, 260, 80, 60, 20, 20));
    g.fill(new CubicCurve(400, 260, 440, 260, 400, 320, 480, 320));
    g.draw(new CubicCurve(400, 260, 440, 260, 400, 320, 480, 320));
    g.setPaint(texturePaint);
    g.draw(new Line(20, 400, 80, 340));
    g.fill(new Rectangle(100, 340, 80, 60));
    g.draw(new Rectangle(100, 340, 80, 60));
    g.fill(new Ellipse(200, 340, 80, 60));
    g.draw(new Ellipse(200, 340, 80, 60));
    g.fill(new RoundRectangle(300, 340, 80, 60, 20, 20));
    g.draw(new RoundRectangle(300, 340, 80, 60, 20, 20));
    g.fill(new CubicCurve(400, 340, 440, 340, 400, 400, 480, 400));
    g.draw(new CubicCurve(400, 340, 440, 340, 400, 400, 480, 400));
  }

  public static void main(String[] args) {
    Example6Graphics graphicsExample = new Example6Graphics();
    graphicsExample.setVisible(true);
    Swing.startEventLoop();
  }

}
